package com.memoir.jpa.config;

/**
 * @author ldm
 * @since 2017-11-27
 */

import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.AuditorAware;

//可以把创建人和修改人自动添加进去
@Configuration
public class AuditConfig implements AuditorAware<String> {
    @Override
    public String getCurrentAuditor() {

        return "修改人|创建人";
        //    SecurityContext ctx = SecurityContextHolder.getContext();
        //    if (ctx == null) {
        //        return null;
        //    }
        //    if (ctx.getAuthentication() == null) {
        //        return null;
        //    }
        //    if (ctx.getAuthentication().getPrincipal() == null) {
        //        return null;
        //    }
        //    Object principal = ctx.getAuthentication().getPrincipal();
        //    if (principal.getClass().isAssignableFrom(Long.class)) {
        //        return (Long) principal;
        //    } else {
        //        return null;
        //    }
    }
}